﻿using UnityEngine;
using UnityEditor;
using System.Collections;

namespace TCG
{
	public static class TextureSerializer
	{
		/// <summary>
		/// 将texture打包到目标文件中。
		/// </summary>

		public static void Serialize (Texture texture)
		{
			// 检查路径是否合法
			string targetPath = GameEditorTools.GetPathForSerilize (texture);
			if (string.IsNullOrEmpty (targetPath))
			{
				throw new System.Exception (string.Format ("贴图{0}应该位于{1}文件夹或其子文件夹中", texture.name, GameEditorTools.SerializableSourceDir));
			}
			
			// 检查贴图命名
			CommonTools.ParseAssetIdFromName (texture.name);

			// 打包贴图
			BuildPipeline.BuildAssetBundle (texture, null, targetPath, BuildAssetBundleOptions.CompleteAssets, GameEditorTools.GetBuildTarget ());
			AssetDatabase.Refresh ();
		}

	}
}
